/*
 * Copyright (c) 2022 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import { isBMP, isGIF, isJPG, isPNG, isTIF } from './imtype.js';
import { bmpData } from './bmpdata.js';
import { gifData } from './gifdata.js';
import { jpgData } from './jpgdata.js';
import { pngData } from './pngdata.js'
import { tifData } from './tifdata.js'

function isBMP_Test() {
  let result;
  const startTime = Date.now();
  for (let index = 0; index < 100000; index++) {
    result = isBMP(bmpData);
  }
  const endTime = Date.now();
  if (result != true) {
    throw Error('imtype_isBMP error');
  }
  print(`imtype_isBMP: ${endTime - startTime} ms`);
}

function isGIF_Test() {
  let result;
  const startTime = Date.now();
  for (let index = 0; index < 100000; index++) {
    result = isGIF(gifData);
  }
  const endTime = Date.now();
  if (result != true) {
    throw Error('imtype_isGIF error');
  }
  print(`imtype_isGIF: ${endTime - startTime} ms`);
}

function isJPG_Test() {
  let result;
  const startTime = Date.now();
  for (let index = 0; index < 100000; index++) {
    result = isJPG(jpgData);
  }
  const endTime = Date.now();
  if (result != true) {
    throw Error('imtype_isJPG error');
  }
  print(`imtype_isJPG: ${endTime - startTime} ms`);
}

function isPNG_Test() {
  let result;
  const startTime = Date.now();
  for (let index = 0; index < 100000; index++) {
    result = isPNG(pngData);
  }
  const endTime = Date.now();
  if (result != true) {
    throw Error('imtype_isPNG error');
  }
  print(`imtype_isPNG: ${endTime - startTime} ms`);
}

function isTIF_Test() {
  let result;
  const startTime = Date.now();
  for (let index = 0; index < 100000; index++) {
    result = isTIF(tifData);
  }
  const endTime = Date.now();
  if (result != true) {
    throw Error('imtype_isTIF error');
  }
  print(`imtype_isTIF: ${endTime - startTime} ms`);
}

isBMP_Test();
isGIF_Test();
isJPG_Test();
isPNG_Test();
isTIF_Test();